package com.dh.spring.common;

import io.netty.handler.codec.http.cookie.Cookie;
import lombok.Data;

import java.io.Serializable;
import java.nio.channels.SocketChannel;
import java.nio.charset.CharsetEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

@Data
public class HttpResponse implements Serializable {

    public enum Code {
        TYPE1(200, "请求并且解析请求数据成功"),
        TYPE2(300, "请求类型错误"),
        TYPE3(500, "socket数据解析失败，无法分隔数据或分隔失败，请保证此次请求为Http请求");

        private final int code;
        private final String data;

        Code(int code, String data) {
            this.code = code;
            this.data = data;
        }

        public int getCode() {
            return code;
        }

        public String getData() {
            return data;
        }
    }

    //TODO 响应状态码
    private Code code;

    //TODO 响应返回数据
    private StringBuffer bodyData = new StringBuffer("");

    // 时间格式化工具
    public static SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", Locale.CHINA);

    // 编码字符集
    private CharsetEncoder encoder;

    // 响应的Content-Type
    private String contentType = "text/html;charset=utf-8";

    // 响应头
    private Map<String, String> headers = new HashMap<String, String>();

    // 响应cookie
    private List<Cookie> cookies = new ArrayList<Cookie>();

    // 客户端输出通道
    private SocketChannel out;

    public HttpResponse() {
        this.code = Code.TYPE1;
    }

    public static HttpResponse getInstance() {
        HttpResponse httpResponse = new HttpResponse();
        httpResponse.setCode(Code.TYPE1);
        return httpResponse;
    }

}
